package com.honestpeak.datafusion.web;

import com.honestpeak.core.datasource.DataSourceContextHolder;
import com.honestpeak.core.datasource.DataSourceType;
import com.honestpeak.datafusion.mapper.ClubMemberDistMapper;
import com.honestpeak.datafusion.mapper.ClubMemberInfoMapper;
import com.honestpeak.datafusion.mapper.DepartmentMapper;
import com.honestpeak.datafusion.model.Department;
import com.honestpeak.datafusion.model.SelectClass;
import com.honestpeak.datafusion.model.selectMajory;
import com.honestpeak.datafusion.service.ClubMemberDistService;

import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 学生数据
 */
@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    ClubMemberDistService clubMemberDistService;
    
	@Autowired
	private ClubMemberInfoMapper clubMemberInfoMapper;
	
	@Autowired
	private DepartmentMapper departmentMapper;
	
    /**
     * 查询学生个人数据
     * @return
     */    
    @RequestMapping("/people")
    public ModelAndView People(ModelAndView mav){
        //切换数据库
    	DataSourceContextHolder.setDbType(DataSourceType.SPORTS);
    	mav.addObject("yearTermList", clubMemberInfoMapper.getAllYearTerm());
        List<String> yearList = clubMemberDistService.getYearTermInfo();
        mav.addObject("yearList", yearList);
        DataSourceContextHolder.clearDbType();
        mav.setViewName("student/people");
        return mav;
    }

    /**
     * 查询班级数据
     * @return
     */    
    @RequestMapping("/class")
    public ModelAndView Class(ModelAndView mav){
        //切换数据库
    	DataSourceContextHolder.setDbType(DataSourceType.SPORTS);
    	mav.addObject("yearTermList", clubMemberInfoMapper.getAllYearTerm());
    	mav.addObject("departList",departmentMapper.selectAll());
    	mav.setViewName("student/class");
        return mav;
    }

    /**
     * 班级各俱乐部人数分布
     * @param departId 院系Id
     * @param claId 班级ID
     * @param yearTermId //学年学期
     * @return
     */
    @RequestMapping(value = "/getClubSizeDistribution", method = RequestMethod.GET)
    @ResponseBody
    public Object getClubSizeDistribution(@RequestParam(value = "departId",required = true) Long departId,
                                          @RequestParam(value = "claId", required = true)  Long claId,
                                          @RequestParam(value = "yearTermId", required = true) Long yearTermId ){
        return clubMemberDistService.getClubSizeDistribution(departId, claId, yearTermId);
    }
    
    /**
     * 根据majoryid查询班级信息
     */
    @RequestMapping(value="/findClass",method=RequestMethod.GET)
    @ResponseBody
    public Object findClass(@RequestParam(value="majoryId",required=true)long majoryId) {
    	DataSourceContextHolder.setDbType(DataSourceType.SPORTS);
    	List<SelectClass> classList=departmentMapper.selectClassByDepartId(majoryId);
    	return classList;
    }
    
    /**
     * 
    * @Title: findMajory
    * @Description: TODO(根据departmentId查询major)
    * @param @param departId
    * @param @return    参数
    * @return Object    返回类型
    * @throws
     */
    @RequestMapping(value="findMajory",method=RequestMethod.GET)
    @ResponseBody
    public Object findMajory(@RequestParam(value ="department",required=true)long departId) {
    	DataSourceContextHolder.setDbType(DataSourceType.SPORTS);
    	List<selectMajory> majoryList=departmentMapper.selectMajoryByDepartId(departId);
    	return majoryList;
    }
    
    /**
     * 班级体育成绩各层次人数
     */
    @RequestMapping(value="/classNumScore",method=RequestMethod.GET)
    @ResponseBody
    public Object getClassNumScore(Long departId,Long claId,Long yearTermId ){
        return clubMemberDistService.getClassNumScore(departId, claId, yearTermId);
    }
    
    /**
     * 体育项目累计签到次数
     */
   @RequestMapping(value="/getSignSecondNum",method=RequestMethod.GET)
    @ResponseBody
    public Object getSignSecondNum(Long yearTermId,String studentNo ){
        return clubMemberDistService.getSignSecondNum(yearTermId,studentNo);
    }
}

